/*
 * from : http://zhedahht.blog.163.com/blog/static/25411174200741295930898/
 */

#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/typeof/typeof.hpp>

void reorder( std::vector< int > &v, bool (*fun)( int n ) )
{
	if( v.empty() )
		return;
	std::vector< int >::iterator begin = v.begin();
	std::vector< int >::iterator end = v.begin() + v.size() - 1;
	while( begin < end ) {
		while( begin < end && !fun( *begin ) ) ++begin;
		if( begin >= end )
			break;
		while( begin < end && fun( *end ) ) --end;
		if( begin >= end )
			break;
		std::swap( *begin, *end );
	}
}

bool isEven( int n )
{
	return (n & 1) == 0;
}

int main( int argc, char *argv[] )
{
	std::vector< int > v;
	for( int i = 1; i < argc; ++i ) {
		v.push_back( atoi( argv[i] ) );
	}

	for( BOOST_AUTO( it, v.begin() ); it != v.end(); ++it ) {
		if( v.begin() != it )
			std::cout << ", ";
		std::cout << *it;
	}
	std::cout << std::endl;

	reorder( v, isEven );

	for( BOOST_AUTO( it, v.begin() ); it != v.end(); ++it ) {
		if( v.begin() != it )
			std::cout << ", ";
		std::cout << *it;
	}
	std::cout << std::endl;

}

